//
//  M_Report.m
//  suRead
//
//  Created by lidi on 15/11/11.
//  Copyright © 2015年 bao. All rights reserved.
//

#import "M_Report.h"

@implementation M_Report
+ (NSDictionary *)JSONKeyPathsByPropertyKey
{
    return @{
             @"f_id": @"id",
             @"f_catid": @"catid",
             @"f_title": @"title",
             @"f_thumb": @"thumb",
             @"f_inputtime": @"inputtime",
             @"f_isreply": @"isreply",
             @"f_content": @"content",
             @"f_comments": @"comments",
             @"f_reply": @"reply",
             @"f_commentsUrl": @"commentsUrl",
             @"f_replystate":@"replystate",
             @"f_square":@"square",
             @"f_commentid":@"commentid",
             @"f_url":@"url",
             @"f_imgs": @"imgs"
             };
}

+ (NSValueTransformer *)f_squareJSONTransformer {
    
    return [MTLValueTransformer transformerUsingForwardBlock:^(NSNumber *value_, BOOL *success, NSError **error){
        
        if (!value_) {
            return @(0);
        }
        
        return @([value_ integerValue]);
        
    } reverseBlock:^(NSString *id_, BOOL *success, NSError **error) {
        return id_;
    }];
    
}

+ (NSValueTransformer *)f_commentsJSONTransformer {
    
    return [MTLValueTransformer transformerUsingForwardBlock:^(NSNumber *value_, BOOL *success, NSError **error){
        
        if (!value_) {
            return @(0);
        }
        
        return @([value_ integerValue]);
        
    } reverseBlock:^(NSString *id_, BOOL *success, NSError **error) {
        return id_;
    }];
    
}

+ (NSValueTransformer *)f_replystateJSONTransformer {
    
    return [MTLValueTransformer transformerUsingForwardBlock:^(NSNumber *value_, BOOL *success, NSError **error){
        
        if (!value_) {
            return @(0);
        }
        
        return @([value_ integerValue]);
        
    } reverseBlock:^(NSString *id_, BOOL *success, NSError **error) {
        return id_;
    }];
    
}


+ (NSValueTransformer *)f_inputtimeJSONTransformer {
    
    return [MTLValueTransformer transformerUsingForwardBlock:^(NSNumber *value_, BOOL *success, NSError **error){
        
        if (!value_) {
            return @"";
        }
        
        double timeInterval = [value_ doubleValue];
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateStyle:NSDateFormatterMediumStyle];
        [formatter setTimeStyle:NSDateFormatterShortStyle];
        [formatter setDateFormat:@"MM-dd HH:mm"];
        
        //时间戳转时间的方法
        NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:timeInterval];
        NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];
        
        return confromTimespStr;
        
    }];
    
}

@end
